#include "VectorialRanker.h"
#include <list>
#include "../WellSizedVector2.h"
#include <iostream>
#include <math.h>

using namespace std;

VectorialRanker::VectorialRanker(vector<double> values) 
:alphaValues(values)
{}

vector<double> VectorialRanker::getRank(vector<WellSizedVector2> wsvVector) {
//	cout << "AAAAAAA" << endl;
//	cout << wsvVector[0].listDocs() << endl;
	uint numIds = wsvVector[0].getVectorSize();
	double alphaSquareSum = 0;
	for (uint j = 0; j < alphaValues.size(); j++) {
		alphaSquareSum += alphaValues[j]*alphaValues[j];
	}
	vector<double> ranks(numIds);
	vector<uint> numElements(alphaValues.size());
	for (uint i = 0; i < numIds; i++) {
		ranks[i] = 0;
		double elementsSquareSum = 0;
		for (uint j = 0; j < alphaValues.size(); j++) {
			numElements[j] = wsvVector[j].getSpecificNumElements(i);
			ranks[i] += alphaValues[j]*numElements[j];
			elementsSquareSum += numElements[j]*numElements[j];
		}
		ranks[i] = ranks[i] / sqrt(alphaSquareSum*elementsSquareSum);
	}
	return ranks;
}
